<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Document</title>
</head>
<body></body>
<script>
    /**
     * @description:
     * @param arr 需要遍历的数组
     * @param index 下标
     * @param result 储存结果
     * @param operationEle 每一次遍历循环的逻辑操作
     * @param operationResult 所有逻辑操作执行完后的结果
     * @return {*}
     */
    function operation(
        arr = [],
        index = 0,
        result = [],
        operationEle = (ele, i) => {
        },
        operationResult = result => {
        }) {
        if (index < 0) {
            operationResult(result)
        } else {
            operationEle(arr[index], index).then(r => {
                result.push(r)
                let next = index - 1
                operation(arr, next, result, operationEle, operationResult)
            })
        }
    }


    //绘制自定义的线
    function polyline(val) {
        let that = this
        var convertor = new BMap.Convertor()
        let lineData = []
        let array2 = []
        this.pointCount = 0
        const lineArray = val.linecoord
        let pointpolyLineArr

        const result = []
        this.operation(
            lineArray,
            lineArray.length - 1,
            result,
            (item, index) => {
                return new Promise((resolve, reject) => {
                    pointpolyLineArr = []
                    let result = new BMap.Point(item[0], item[1])
                    pointpolyLineArr.push(result)
                    convertor.translate(pointpolyLineArr, 1, 5, data => {
                        lineData.push(data.points[0])
                        that.lineList.push(data.points[0])
                        array2.push(new BMap.Point(item[0], item[1]))
                        resolve(data)
                    })
                    console.log(index)
                })
            },
            result => {
                var polyline = new BMap.Polyline(lineData, {
                    strokeColor: 'RGB(8,146,251)',
                    strokeWeight: 10,
                    strokeOpacity: 1
                })
                polyline.name = 'lw'
                polyline.addEventListener('click', function () {
                    that.$emit('dlInfo', val)
                })
                that.map.addOverlay(polyline)
            }
        )
    }


</script>
</html>
